import os

"""

"""
def GetAllSubFile(root_dir):
	img_list = []
	sub_files = []
	tmp_sub_files = os.listdir(root_dir)
	for tmp_file in tmp_sub_files:
		sub_files.append(os.path.join(root_dir, tmp_file))
	#print("sub_files=",sub_files)
	while (len(sub_files) != 0):
		tmp_sub_dir = []
		for i in range(len(sub_files)):
			tmp_file = sub_files[i]
			if os.path.isfile(tmp_file):
				img_list.append(tmp_file)
			if os.path.isdir(tmp_file):
				tmp_dirs = os.listdir(tmp_file)
				for tmp_dir in tmp_dirs:
					tmp_sub_dir.append(os.path.join(tmp_file, tmp_dir))
		sub_files = tmp_sub_dir
		#print("sub_files=",sub_files)
		#print("img_list=",img_list)

	return img_list

def test_GetAllSubFile():

	test_root_dir = "./test_dir"

	os.makedirs(test_root_dir)
	a_dir = os.path.join(test_root_dir,"a_dir")
	os.makedirs(a_dir)
	a1_file = os.path.join(a_dir,"a1_file")
	with open(a1_file, "w") as f:
		f.write("test")
	
	b_dir = os.path.join(test_root_dir,"b_dir")
	os.makedirs(b_dir)
	b1_file = os.path.join(test_root_dir,"c1_file")
	with open(b1_file, "w") as f:
		f.write("test")
		
	c1_file = os.path.join(b_dir,"b1_file")
	with open(c1_file, "w") as f:
		f.write("test")
			
	print(GetAllSubFile(test_root_dir))
	
	os.remove(c1_file)
	os.remove(b1_file)
	os.remove(a1_file)
	os.rmdir(b_dir)
	os.rmdir(a_dir)
	os.rmdir(test_root_dir)

if __name__ == "__main__":
	test_GetAllSubFile()
